<script src="js/graphics.js"></script>
<?php
if(checkAdmin()){
	if(isset($_POST['submit'])){
		if(strlen($_POST['moodName']) != 0){
			ini_set('upload_max_filesize', '320000000');
			require_once("classes/Mood.class.php");
			$insertMood = new Mood($_POST);
			$insertMood->save($_FILES['picture'],$_FILES['music']);
		}
		else
		{
			echo '<div class="centered">'.getErrMess(36).'</div>';
		}
	}
?>
    <h2>Gérer les humeurs</h2>
    <p>Cette page vous permet de créer une humeur, ou de modifier une existante. Saisissez le nom de l'humeur et importez son image et sa musique. Attention : seul le format .mp3 est supporté pour les musiques.</p>
    <div class="centered">
        <div id="elementList">
            <?php
                require_once("classes/HumeurDatabase.class.php");
				require_once("classes/Galery.class.php");
				require_once("classes/Mood.class.php");
                $bd = new HumeurDatabase();
                $bd->connect();
				$gallery = new Galery('',error("Aucune humeur n'est disponible pour le moment."));
                $allMoods = $bd->query("SELECT * FROM moods ORDER BY position ASC");
                while($moodData = mysql_fetch_assoc($allMoods)){
					if(isset($_POST['submit'.$moodData['moodName']])){
						$mood = new Mood($moodData['moodName']);
						$mood->setPosition($_POST[$moodData['moodName'].'position']);
						$mood->update($_FILES['picture'.$moodData['moodName']],$_FILES['music'.$moodData['moodName']]);
					}
				}
				$allMoods = $bd->query("SELECT * FROM moods ORDER BY position ASC");
				while($moodData = mysql_fetch_assoc($allMoods)){
					$mood = new Mood($moodData['moodName']);
					$gallery->push($mood);
                }
				echo $gallery;
            ?>
            <div class="centered existingColorBloc">
                <div class="colorForm">
                    <form action="" method="post" enctype="multipart/form-data">
                        <input type="hidden" name="MAX_FILE_SIZE" value="300000000">
                        <input type="text" name="moodName" placeholder="Nom de l'humeur" /><br/><br/>
                        Image : 
                        <input type="file" name="picture" placeholder="Image" /><br/>
                        Musique d'ambiance : 
                        <input type="file" name="music" placeholder="Musique" /><br/>
                        <input type="submit" name="submit">
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="centered"><span class="buttonBloc grey"><a href="index.php?module=myaccount"><img src="img/back.png" alt="Retour"/>Retour au compte</a></span></div>
<?php
}
?>